package com.hopes.bizz.protocol.hj212.bo;

import io.netty.channel.ChannelId;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;

/**
 * 客户端通道关系表
 * @author jie.dai
 */
@Slf4j
public class ClientChannelRel {

    private static final HashMap<String, ChannelId> MANAGER = new HashMap<>();

    /**
     * 设置对应关系
     *
     */
    public static void put(String clientId, ChannelId channelId) {
        log.debug("新的客户端-通道对应关系建立 ===> clientId:{}, channelId:{}", clientId, channelId);
        MANAGER.put(clientId, channelId);
    }

    /**
     * 获取对应通讯通道
     *
     */
    public static ChannelId get(String clientId) {
        return MANAGER.get(clientId);
    }

    /**
     * 移除对应通讯通道
     *
     */
    public static void removeChannelId(ChannelId channelId) {
        MANAGER.values().remove(channelId);
    }


    public static void output() {
        for (HashMap.Entry<String, ChannelId> entry : MANAGER.entrySet()) {
            log.debug("channel key:{}, ChannelId:{}", entry.getKey(), entry.getValue());
        }
    }
}
